package org.lql.algo.codecrush.hot100.greedy;

/**
 * @author: liangqinglong
 * @date: 2025-09-16 09:02
 * @description: 55. 跳跃游戏 <a href="https://leetcode.cn/problems/jump-game/description/?envType=study-plan-v2&envId=top-100-liked">...</a>
 **/
public class CanJump {

	public boolean canJump(int[] nums) {
		if (nums == null || nums.length == 0) {
			return false;
		}
		int n = nums.length;
		int rightMost = 0;
		for (int i = 0; i < n; i++) {
			if (i <= rightMost) {
				rightMost = Math.max(rightMost, i + nums[i]);
				if (rightMost >= n - 1) {
					return true;
				}
			}
		}
		return false;
	}

	public static void main(String[] args) {
		CanJump canJump = new CanJump();
		System.out.println(canJump.canJump(new int[]{2, 3, 1, 1, 4}));
		System.out.println(canJump.canJump(new int[]{3, 2, 1, 0, 4}));
		System.out.println(canJump.canJump(new int[]{0}));
	}
}
